//
//  LFBCycleView.m
//  loveFreshBeen
//
//  Created by Feng on 2017/7/9.
//  Copyright © 2017年 feng. All rights reserved.
//

#import "LFBCycleView.h"
#import "CycleView.h"
#import "SDCycleScrollView.h"
#import "LFBCycleModel.h"

@interface LFBCycleView () <SDCycleScrollViewDelegate>

@property(nonatomic,weak) CycleView *cycleView;

@end

@implementation LFBCycleView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self setupUI];
        
        NSLog(@"~~~~~创建LFBCycleView");
    }
    return self;
}

- (void)setupUI
{
//    CycleView *cycleView = [[CycleView alloc] initWithFrame:self.bounds];
//    self.cycleView = cycleView;
//    
//    [self addSubview:cycleView];
}

- (void)setFocusArray:(NSArray *)focusArray
{
    _focusArray = focusArray;
    
    //设置图片链接数组
    NSMutableArray *imageURLArray = [NSMutableArray array];
    for (LFBCycleModel *model in focusArray) {
        [imageURLArray addObject:model.img];
    }
    
    // 网络加载图片的轮播器
    SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:self.frame delegate:self placeholderImage:[UIImage imageNamed:@"v2_placeholder_square"]];
    cycleScrollView.imageURLStringsGroup = imageURLArray;
    
    [self addSubview:cycleScrollView];
    
//    CycleView *cycleView = [[CycleView alloc] initWithFrame:self.bounds];
//    self.cycleView = cycleView;
//    
//    [self addSubview:cycleView];
//    
//    //刷新collectionView
//    [self.cycleView.collectionView reloadData];
//    //创建pageControl
//    [self.cycleView setupPageControlWithPageCount:focusArray.count];
//    //启动计时器
//    [self.cycleView createTimer];
    
//    NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:1];
//    
//    [self.cycleView.collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionLeft animated:NO];
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    LFBCycleModel *model = self.focusArray[index];
    
    [[NSNotificationCenter defaultCenter] postNotificationName:LFBHomeCycleViewDidSelectedNotification object:self userInfo:@{KHomeCycleViewURL: model.toURL}];
}

@end
